<extend name="Layout/ins_page" />
<block name="content">
{:W('PageHeader/simple',array('name'=>'选择题目','search'=>'N'))}

<div class="operate panel panel-default">	<div class="panel-body">
	<div class="pull-right">
		<a  onclick="save();" class="btn btn-sm btn-primary">确定</a>
		<a  onclick="myclose();" class="btn btn-sm btn-primary">关闭</a>
	</div>
</div>
</div>
<div class="row">
	<div class="col-sm-5">
		<div class="row form-horizontal">
			<div class="form-group">
				<b>题目</b>
			</div>
		</div>
		<div class="row popup_tree_menu" style="height:403px;">
			<div id="tag" style="width:100%;height:100%;" class="dp tag">
				{$list_popup}
			</div>
		</div>
	</div>
	<div class="col-sm-7" >
		<div class="row form-horizontal">
			<div class="form-group">
				<label class="col-sm-2 control-label" ></label>
				<div class="col-sm-10">
					<b>已选</b>
					<span id="rc_count"></span>
				</div>
			</div>
		</div>
		<div class="row form-horizontal" >
			<div class="form-group">
				<label class="col-sm-2 control-label" > <a onclick="add_address('rc');" class="btn btn-sm btn-primary"> <i class="fa fa-double-angle-right"></i> </a> </label>
				<div class="col-sm-10">
					<div id="rc" style="width:100%;height:413px;overflow:hidden">
						<select size="6" style="height:100%;width:100%;"></select>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
</block>
<block name="js">
<script type="text/javascript">
	function save() {
		$("#tag_wrap", parent.document).hide();
		$("#tag_wrap", parent.document).html("");

		$("#rc select option").each(function(i) {
			//email=($(this).html().split(";")[1].split("&")[0]);
			$("#tag_wrap", parent.document).append('<span  emp_no="' + $(this).val() + '">' + jQuery.trim($(this).text()) + ' </span>');
		});

		$("#tag_wrap span b", parent.document).each(function() {
			$(this).remove();
		})

		$("#tag_wrap span", parent.document).each(function() {
			$(this).append("<b>;</b>   ");
		})
		$("#tag_wrap span", parent.document).last().find("b").remove();

		$("#tag_wrap", parent.document).show();

		myclose();
	}


	$(document).ready(function() {
		$("#tag .tree_menu  a").click(function() {//点击节点时读取相应的数据
			$("#tag .tree_menu a").each(function() {
				$(this).attr("class", "");
			});
			$(this).attr("class", "active");
			return false;
			//禁止连接生效
		});

		$("#tag .tree_menu  a").dblclick(function() {//点击节点时读取相应的数据
			$("#tag .tree_menu a").removeClass("active");
			$(this).attr("class", "active");
			add_address('rc');
			return false;
			//禁止连接生效
		});

		$("#rc  select").live("dblclick", function() {// 双击添加到收件人 因后添加的数据 所以需要用live函数
			$(this).find("option:selected").remove();
			$("#rc_count").text("(" + $("#rc select option").length + ")");
		});

		$("#rc select").droppable({
			activeClass : "ui-state-default",
			hoverClass : "ui-state-hover",
			accept : ":not(.ui-sortable-helper)",
			drop : function(event, ui) {
				$text = ui.draggable.text();
				$val = ui.draggable.find("input").val();
				if ($("#rc select option[value='" + $val + "']").val() == undefined) {
					$option = $("<option></option>");
					$option.val($val);
					$option.text($text).appendTo(this);
					$("#rc_count").text("(" + $("#rc select option").length + ")");
				};
			},
		}).sortable({
			items : "option:not(.placeholder)",
			sort : function() {
				// gets added unintentionally by droppable interacting with sortable
				// using connectWithSortable fixes this, but doesn't allow you to customize active/hoverClass options
				$(this).removeClass("ui-state-default");
			}
		});
	})
	//最终确认

	function add_address(name) {
		$tag_id = $("#tag a.active").attr("node");
		$tag_name = $("#tag a.active span").text();

		$text = $tag_name;
		$val = "tag_" + $tag_id;
		if ($("#" + name + " select option[value='" + $val + "']").val() == undefined) {
			$option = $("<option></option>");
			$option.val($val);
			$option.text($text).appendTo("#" + name + " select");
			$("#" + name + "_count").text("(" + $("#" + name + " select option").length + ")");
		};
	}

	//-->
</script>
</block>